<%@ page import="Domain.UserClient.ButtonsFunctions"%>
<%@page import="Domain.DataManager"%>
<%@ page import="java.util.*"%>
<%@ page import="objects.*"%>

<%
	DataManager dm = (DataManager) (session.getAttribute("dm"));
	ButtonsFunctions bf = (ButtonsFunctions) (session
			.getAttribute("bf"));
	if (dm == null) {
		response.sendRedirect("Welcome.jsp");
	} else if (dm.getUserStatus() == DataManager.CONNECTED) {
		response.sendRedirect("ChooseForum.jsp");
	} else {

		String userName = request.getParameter("username");
		String password = request.getParameter("password");

		bf.processRegisterUser(userName, password);

		if (!dm.getRegistered()) {
			response.sendRedirect("RegisterFailed.jsp");
		} else {
			bf.processConnect(userName, password);

			if (!dm.getConnected()) {
				response.sendRedirect("RegisterFailed.jsp");
			} else {
				bf.processAddUser();
				response.sendRedirect("Logout.jsp");
			}
		}

	}
%>
